from django.shortcuts import render, HttpResponse, redirect
from App01 import models


# Create your views here.
def Login(request):
    if request.method == "POST":
        usr = request.POST.get('user')
        pwd = request.POST.get('pwd', None)
        try:
            user_obj = models.User.objects.get(username=usr)
        except Exception:
            return HttpResponse('用户名不正确')
        if user_obj and pwd == user_obj.password:
            return redirect('/Index/')
        else:
            return HttpResponse('密码不正确')
    return render(request, 'login.html')


def Index(request):
    return render(request, "index.html")
